package com.ruoyi.component.mqtt;

import com.ruoyi.pojo.OnlineOutletMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cj
 */
@Service
public class MqttCallbackHandler {

    private static final Logger logger = LoggerFactory.getLogger(MqttCallbackHandler.class);

    @Autowired
    OnlineOutletMap onlineOutletMap;


    public void handler(String topic, String payload){
        // 根据topic分别进行消息处理。
        //智能插座订阅的前缀
        String prefix = "WifiSock";
        if (topic.startsWith(prefix)){
            // 获取智能插座编码
            String outletId = topic.split("/")[1];
            Object objCache = onlineOutletMap.get(outletId);
            if (objCache == null){
                //新检测到的插座
//                onlineOutletMap.put(outletId,)
            }
            System.out.println(onlineOutletMap);
        }
    }

}
